package me.work.pay.jsyl.mvp.model;

import android.app.Application;

import com.blankj.utilcode.util.SPUtils;
import com.google.gson.Gson;
import com.jess.arms.integration.IRepositoryManager;
import com.jess.arms.mvp.BaseModel;

import com.jess.arms.di.scope.ActivityScope;

import java.text.SimpleDateFormat;
import java.util.Map;

import javax.inject.Inject;

import io.reactivex.Observable;
import me.work.pay.jsyl.app.Constants;
import me.work.pay.jsyl.mvp.contract.OrderListContract;
import me.work.pay.jsyl.mvp.model.api.CommonApi;
import me.work.pay.jsyl.mvp.model.entity.OrderData;


/**
 * ================================================
 * Description:
 * <p>
 * Created by MVPArmsTemplate on 09/14/2020 08:45
 * <a href="mailto:jess.yan.effort@gmail.com">Contact me</a>
 * <a href="https://github.com/JessYanCoding">Follow me</a>
 * <a href="https://github.com/JessYanCoding/MVPArms">Star me</a>
 * <a href="https://github.com/JessYanCoding/MVPArms/wiki">See me</a>
 * <a href="https://github.com/JessYanCoding/MVPArmsTemplate">模版请保持更新</a>
 * ================================================
 */
@ActivityScope
public class OrderListModel extends BaseModel implements OrderListContract.Model {
    @Inject
    Gson mGson;
    @Inject
    Application mApplication;

    @Inject
    public OrderListModel(IRepositoryManager repositoryManager) {
        super(repositoryManager);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        this.mGson = null;
        this.mApplication = null;
    }

    @Override
    public Observable<OrderData> search_order(Map<String, Object> map) {
        map.put("shopId", SPUtils.getInstance().getString(Constants.sp_shop_id));
        map.put("deviceId",Constants.sn);//设备ID
        long currentTime = System.currentTimeMillis();
        String timeNow = new SimpleDateFormat("yyyy-MM-dd").format(currentTime);
        map.put("start",timeNow+" 00:00:00");//起始时间
        map.put("end",timeNow+" 23:59:59");//结束时间
        map.put("orderStatus","1");//订单状态
        map.put("source","api");//固定值
        map.put("pageSize","20");
//        map.put("getType","orders");//获取信息类型，默认为空全部返回；statistics：只返回统计信息；orders： 只返回订单信息
        return mRepositoryManager.obtainRetrofitService(CommonApi.class).load_order(map);
    }
}